package service;

import dao.BlogDao;
import entity.Blog;

import java.util.List;

public class BlogService {
    private final BlogDao blogDao = new BlogDao();

    public List<Blog> getHotBlogs(String orderBy) {
        return blogDao.getHotBlogs(orderBy);
    }

    public Blog getBlogById(int blogId) {
        return blogDao.getBlogById(blogId);
    }

    public void incrementViewCount(int blogId){
        blogDao.incrementViewCount(blogId);
    }

    public boolean isUserLikedBlog(int userId, int blogId){
        return blogDao.isUserLikedBlog(userId, blogId);
    }

    public boolean toggleLikeBlog(int userId, int blogId){
        if(blogDao.isUserLikedBlog(userId, blogId)){
            blogDao.unlikeBlog(userId, blogId);
            return true;
        }else{
            blogDao.likeBlog(userId, blogId);
            return false;
        }
    }

    public void createBlog(String title, String content, int authorId) {
        blogDao.createBlog(title, content, authorId);
    }

    public void updateBlog(String title, String content, int blogId) {
        blogDao.updateBlog(title, content, blogId);
    }

    public void deleteBlog(int blogId) {
        blogDao.deleteBlog(blogId);
    }

    public List<Blog> searchBlogsByKeyword(String keyword){
        return blogDao.searchBlogsByKeyword(keyword);
    }

    public List<Blog> getBlogsByAuthorId(int authorId){
        return blogDao.getBlogsByAuthorId(authorId);
    }

    public List<Blog> getBlogsByColumnId(int columnId, String orderBy){
        return blogDao.getBlogsByColumnId(columnId, orderBy);
    }

    public List<Blog> getBlogsWithoutColumn(int userId){
        return blogDao.getBlogsWithoutColumn(userId);
    }

    public boolean toggleTopStatus(int blogId, boolean isTop) {
        return blogDao.setTopStatus(blogId, isTop);
    }

    public List<Blog> getLikedBlogsByUserId(int userId) {
        return blogDao.getLikedBlogsByUserId(userId);
    }

}
